home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 22 code / PCI Driver Sample / NCR_DriverProject / Src / DriverPCIBusUtilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-01  |  2.5 KB  |  104 lines  |  [TEXT/MPCC]

  1. /*                                DriverPCIBusUtilities.c                                */
  2. /*
  3.  * DriverPCIBusUtilities.c
  4.  * Copyright © 1994 Apple Computer Inc. All rights reserved.
  5.  *
  6.  * These low-level routines access the PCI bus registers.
  7.  *
  8.  * Read/Write IO Byte/Long        Use the Expansion Manager interface.
  9.  * Read/Write Byte/Long            Use the preferred memory interface.
  10.  */
  11. /*    .___________________________________________________________________________________.
  12.       | In a production environment, the Read/Write Byte/Word/Long routines will normally    |
  13.       | be implemented by inline code segments (or macros). They are routines here to        |
  14.       | centralize last-chance low-level debug logging.                                    |
  15.       |                                                                                    |
  16.       | Also, note that this function synchronizes I/O after every write. This is            |
  17.       | inefficient, but useful for testing.                                                |
  18.     .___________________________________________________________________________________.
  19. */
  20. #include "NCRDriverPrivate.h"
  21. #define DUMP_ALL    (0 && USE_LOG_LIBRARY)
  22. /*
  23.  * We don't trace these
  24.  */
  25.  
  26. /*
  27.  * Read/write using the device's LogicalAddress.
  28.  */
  29. void
  30. WriteByte(
  31.         unsigned short            chipRegister,
  32.         UInt8                    value
  33.     )
  34. {
  35.         UInt8                    *ptr;
  36.         
  37. #if DUMP_ALL
  38.         {
  39.             Str255                work;
  40.             
  41.             PStrCopy(work, "\pWriteByte(");
  42.             AppendHexLeadingZeros(work, (UInt32) GLOBAL.pciCardBaseAddress, 8);
  43.             PStrCat(work, "\p + ");
  44.             AppendHexLeadingZeros(work, chipRegister, 2);
  45.             PStrCat(work, "\p, ");
  46.             AppendHexLeadingZeros(work, value, 2);
  47.             PStrCat(work, "\p");
  48.             LogString(work);
  49.         }
  50. #endif
  51.         ptr = (UInt8 *) (((UInt8 *) GLOBAL.pciCardBaseAddress) + chipRegister);
  52.         *ptr = value;
  53.         SynchronizeIO();
  54. }
  55.  
  56. void
  57. WriteLong(
  58.         unsigned short            chipRegister,
  59.         long                    value
  60.     )
  61. {
  62.         UInt32                    *ptr;
  63.         
  64. #if DUMP_ALL
  65.         {
  66.             Str255                work;
  67.             
  68.             PStrCopy(work, "\pWriteLong(");
  69.             AppendHexLeadingZeros(work, (UInt32) GLOBAL.pciCardBaseAddress, 8);
  70.             PStrCat(work, "\p + ");
  71.             AppendHexLeadingZeros(work, chipRegister, 2);
  72.             PStrCat(work, "\p, ");
  73.             AppendHexLeadingZeros(work, value, 8);
  74.             PStrCat(work, "\p)");
  75.             LogString(work);
  76.         }
  77. #endif
  78.         ptr = (UInt32 *) (((UInt8 *) GLOBAL.pciCardBaseAddress) + chipRegister);
  79.         *ptr = EndianSwap32Bit(value);
  80.         SynchronizeIO();
  81. }
  82.  
  83. UInt8
  84. ReadByte(
  85.         unsigned short            chipRegister
  86.     )
  87. {
  88.         UInt8                    *ptr;
  89.         
  90.         ptr = (UInt8 *) (((UInt8 *) GLOBAL.pciCardBaseAddress) + chipRegister);
  91.         return (*ptr);
  92. }
  93.  
  94. UInt32
  95. ReadLong(
  96.         unsigned short            chipRegister
  97.     )
  98. {
  99.         UInt32                    *ptr;
  100.         
  101.         ptr = (UInt32 *) (((UInt8 *) GLOBAL.pciCardBaseAddress) + chipRegister);
  102.         return (EndianSwap32Bit(*ptr));
  103. }
  104.